package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.fw.GroupObject;
import com.example.fw.Groups;

public class GroupRemovalTests extends TestBase {
	
	@Test
	public void testSomeGroupCanBeRemoved() throws Exception {
		for (int i = 0; i < 1; i++) {
			Groups oldGroupList = app.getGroupHelper().getGroups();
			GroupObject someGroupToDelete = oldGroupList.getSomeGroupFromList();
			app.getGroupHelper().deleteGroup(someGroupToDelete);
			Groups newGroupList = app.getGroupHelper().getGroups();
			assertThat(newGroupList, equalTo(oldGroupList.withOut(someGroupToDelete)));		//	hamcrest style lesson 4 65:00
		}
	}
	
	@AfterMethod		// lesson 7 ~ 75:00
	public void testUiAndDbConformsWithModel()	{
		if (app.getProperty("ui.check") != null)	{
			Groups modelList = app.getGroupHelper().getGroups();
			Groups uiList = app.getGroupHelper().getUiGroups();
			assertThat(uiList, equalTo(modelList));
		}
		if (app.getProperty("db.check") != null)	{
			Groups modelList = app.getGroupHelper().getGroups();
			Groups dbList = app.getHibernateHelper().getGroups();
			assertThat(dbList, equalTo(modelList));
		}
	}
}